<!DOCTYPE html>
<html lang="zh-cn" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>支付</title>
</head>
<body style="padding-top: 100px">
<script type="text/javascript" th:src="@{/static/jquery3.3.1.js}"></script>
<script type="text/javascript" th:src="@{/static/qrcode.js}"></script>

<a th:href="@{/}" id="gotoIndex">返回主页</a>

<div style="text-align: center">
    <h1>请使用支付宝扫码支付,五分钟未支付自动取消交易。</h1>
    <h1>支付成功后会自动打印文件。</h1>
</div>
<div style="min-width: 500px;max-width:500px;margin: 0 auto">
    <div id="qrcode" style="min-width: 400px"></div>
    <input type="hidden" th:value="${link.getPayAddress()}" id="link">
    <input type="hidden" th:value="${link.getId()}" id="query">
</div>
<div style="min-width: 500px;max-width:500px;margin: 0 auto;text-align: center" id="phonePay">
    <a th:href="${'alipays://platformapi/startapp?appId=20000067&url='+link.getPayAddress()}"
       style="text-decoration: none;color: black;font-size: 80px;font-weight: bold;margin-top: 30px">手机支付宝</a>
</div>
<script type="text/javascript">
    var id = document.getElementById('query').value;
    var index = document.getElementById('gotoIndex').href;
</script>
<script type="text/javascript">
    $(document).ready(function () {
        var timer = setInterval(function setTimer() {
            $.ajax({
                url: '/queryPay',
                type: 'POST',
                data: {'id': id},
                success: function (data, status) {
                    if ('success' == data) {
                        alert("支付成功");
                        window.location.href = '../';
                    }
                }
            });
        }, 5000);

        function IsPC() {
            var userAgentInfo = navigator.userAgent;
            var Agents = ["Android", "iPhone",
                "SymbianOS", "Windows Phone",
                "iPad", "iPod"];
            var flag = true;
            for (var v = 0; v < Agents.length; v++) {
                if (userAgentInfo.indexOf(Agents[v]) > 0) {
                    flag = false;
                    break;
                }
            }
            return flag;
        }

        // if (!IsPC()) {
        //     var phone = document.getElementById('phonePay');
        //     phone.style.display = block;
        // }
    });
</script>
<script type="text/javascript">
    var link = document.getElementById('link').value;
    var qrcode = new QRCode("qrcode", {
        text: link,
        width: 400,
        height: 400,
        colorDark: "#000000",
        colorLight: "#ffffff",
        correctLevel: QRCode.CorrectLevel.H
    });
    // window.location.href = "alipays://platformapi/startapp?appId=20000067&url=" + link;
</script>
</body>
</html>